from math import pi
fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
fruits.append('grape') #末尾追加 无返回值
fruits.pop(2)#不传递索引 删除最后一个 返回被删除的值

fruits.insert(2,'aa') #从指定的索引位置插入元素  只能插入一个
print(fruits)

fruits.remove('apple') #删除apple 只会删除第一个
print(fruits)
b=fruits.pop(2)
print(b)
print(fruits)
c=fruits.count('apple')
print(c)

fruits.reverse()
print(fruits)


list1=[x**2 for x in range(6) if x%2]
print(list1)

list2=[(x,y)  for x in range(6) for y in range(6) if x==y]
print(list2)

list3=[-4, -2, 0, 2, 4]

list4=[x*2 for x in list3]
print(list4)
 
list5=[x for x in list3 if x>=0]
print(list5)
 
 
list6=[abs(x) for x in list3 ]
print(list6)
 
 
list7=[(x,x**2) for x in range(6)]
print(list7)
 
 
 
list8=[round(pi,x) for x in range(10)]
print(list8)

list9=[[1,2,3], [4,5,6], [7,8,9]]
list10=[y for x in list9 for y in x ]
print(list10)

def aa(): 
 t=set()
 t.add('apple')
 t.add('orange')
 t.add('apple')
 t.add('pear')
 print(t)
 print('orange' in t)
 t1=set('abcabcabc')
 t2=set([1,2,3,1,2,3,4])
 a=set('123')
 b=set('234')
 print(t1)
 print(t2)
 print(a&b)
 print(a|b)
 print(a-b)
#  print(list(t))
 s=set('123456')
 print(s)
 print(list(s))

 

aa()

tel = {'jack': 4098, 'sape': 4139}
tel['aa']=23
print(tel)

print('aa' in tel)
print(tel.get('jack'))
print(tel['jack'])
# del tel['aa']
print(tel)
print(list(tel))
print(sorted(tel))
dict1=dict([('a',1),('b',2),('c',3)])
print(dict1)

dict2={x:dict1[x] for x in dict1}

print(dict2)

for i,v in enumerate([10,20,30]):
    print('aa',i,v)

print(dict1.items())

for a,b in dict1.items():
    print(a,b)
    
def fn(a,b,c):
  print(f'a={a},b={b},c={c}')

def fn1(a,b=2,c=3):
    print(f'a={a},b={b},c={c}')
    
fn1(1,c=3,b=2)
fn1(a=1,c=3)


def fn3(a,*arguments,**keywords):
 print(a)
 for v in arguments:
     print(v)
 print('----')
 for v in keywords:
     print(v,keywords[v])

 

fn3('aa',2,3,4,b=2,c=3)
